import ajax from "./ajax";
import mockAjax from "./mockAjax";

// export const reqBaseCategoryList = async () => {
//   try {
//     const result = await ajax.get("/product/getBaseCategoryList");
//     return result;
//   } catch (error) {
//     console.log("BaseCategoryList数据,获取失败", error);
//   }
// };
// 获取三级标题数据
export const reqBaseCategoryList = () =>
  ajax.get("/product/getBaseCategoryList");

// 获取轮播图数据
export const reqGetBannerListData = () => mockAjax.get("/banner");

// 获取floor楼层数据
export const reqGetFloorListData = () => mockAjax.get("/floor");

// 获取search页面数据
export const reqGetGoodsInfoData = (searchParams) =>
  ajax.post("/list", searchParams);

// 获取详情页数据
export const reqGetGoodDetailListData = (skuId) => ajax.get(`item/${skuId}`);

//添加到购物车
export const reqAddOrUpdateCart = (skuId, skuNum) =>
  ajax.post(`/cart/addToCart/${skuId}/${skuNum}`);

//获取购物车数据
export const reqGetShopList = () => ajax.get(`/cart/cartList`);

//更新购物车中数据的选中状态
export const reqChangeCartState = (skuID, isChecked) =>
  ajax.get(`/cart/checkCart/${skuID}/${isChecked}`);

// 当大括号中只有一行代码的时候，可以省略return和大括号
// export const reqChangeAllCartState = (isChecked, skuIdList) =>
//   ajax.post(`/cart/batchCheckCart/${isChecked}`, skuIdList);
export const reqChangeAllCartState = (isChecked, skuIdList) =>
  ajax({
    url: `/cart/batchCheckCart/${isChecked}`,
    method: "post",
    data: skuIdList,
  });

// 删除单条商品
export const reqDelOneShopCartInfo = (skuId) =>
  ajax.delete(`/cart/deleteCart/${skuId}`);

// 批量删除所选商品的函数
export const reqDelSelectedShopCartInfo = (skuIdList) =>
  ajax.delete(`/cart/batchDeleteCart`, { data: skuIdList });

// 获取验证码
export const reqGetVerifyCode = (phone) =>
  ajax.get(`/user/passport/sendCode/${phone}`);

// 注册账户
export const reqUserRegister = (user) =>
  ajax.post(`/user/passport/register`, user);

// 登录
export const reqUserLogin = (user) => ajax.post(`/user/passport/login`, user);

// 登出
export const reqUserLogout = () => ajax.get(`/user/passport/logout`);

//  获取订单交易页信息
export const reqGetTradeInfoData = () => ajax.get("/order/auth/trade");

// 获取用户收货地址信息

export const reqGetUserAddressList = () =>
  ajax.get("/user/userAddress/auth/findUserAddressList");

// 提交订单数据
export const reqSubmitOrder = (tradeNo, tradeInfo) =>
  ajax.post(`/order/auth/submitOrder?tradeNo=${tradeNo}`, tradeInfo);

// 获取订单支付信息 也就是会根据付款接口响应回来的地址生成的二维码
export const reqGetPaymentInfo = (orderId) =>
  ajax.get(`/payment/weixin/createNative/${orderId}`);

// 14. 查询支付订单状态
export const reqGetPayOrderState = (orderId) =>
  ajax.get(`/payment/weixin/queryPayStatus/${orderId}`);
